var stockUrl = basePath + "/sys/report/schoolProperty/stock";
var dataGrid;
var schoolId = $("#userSchoolId").val();

$(function () {
    initSchoolIdValue();
    loadData();
});

function loadData() {
    dataGrid = $('#notice').datagrid({
        url: stockUrl,
        toolbar: '#tb',
        fit: true,
        fitColumns: true,
        border: true,
        pagination: true,
        idField: 'id',
        pageSize: config.pageSize,
        autoRowHeight: 140,
        pageList: config.pageList,
        queryParams: {
            cycleUse: $("#cycleUse").val(),
            minStock: $("#minStock").val(),
            maxStock: $("#maxStock").val(),
			schoolId: schoolId
		},
        nowrap: true,
        striped: true,
        rownumbers: true,
        columns: [[
            {
                field: 'id',
                width: 10,
                align: "center",
                checkbox: true
            },
            {
                field: 'typeName',
                title: '类别名称',
                resizable: true,
                align: "center",
                width: 15
            },
            {
                field: 'cycleUseText',
                title: '是否是消耗品',
                width: 10,
                align: "center"
            },
            {
                field: 'goodsName',
                title: '物品名称',
                width: 15,
                align: "center"
            },
            {
                field: 'goodsAttr',
                title: '物品型号',
                width: 15,
                align: "center"
            },
            {
                field: 'currentStock',
                title: '可用库存',
                width: 10,
                align: "center"
            },
            {
                field: 'totalStock',
                title: '总库存',
                width: 10,
                align: "center"
            },
            {
                field: 'nos',
                title: '物品编号',
                width: 30,
                align: "center"
            }
        ]],
        onAfterEdit: function (rowIndex, rowData, changes) {
            if (rowData.id) {
                changes.id = rowData.id;
                changes.resourceRange = $("#resourceRange").val();
                changes.schoolId = schoolId;
                addmodify(changes);
            } else {
                rowData.resourceRange = $("#resourceRange").val();
                rowData.schoolId = schoolId;
                addmodify(rowData);
            }
        }
    });
}

function exportToExcel(searchForm, exportUrl) {
    $("#" + searchForm).attr('action', exportUrl);
    $("#" + searchForm).submit();
}

function reload() {
    dataGrid.datagrid("clearSelections");
    searchForm("searchForm");
}

function searchForm(formId) {
    dataGrid.datagrid('load', $.serializeObject($('#' + formId)));
}

function resetForm(formId) {
    $("#" + formId)[0].reset();
    $("#applyStartDate").datebox('setValue', '');
    $("#applyEndDate").datebox('setValue', '');
}